package com.weilele.leisure.time.ui.module.mine


import android.os.Bundle
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.weilele.base.library.BaseBindingFragment
import com.weilele.base.library.FragmentContainerActivity
import com.weilele.leisure.time.R
import com.weilele.leisure.time.databinding.FragmentAboutAppBinding
import com.weilele.leisure.time.ui.SettingConfig
import com.weilele.mvvm.utils.activity.toast
import com.weilele.mvvm.utils.appVersionName


class AboutAppFragment : BaseBindingFragment<FragmentAboutAppBinding>() {
    companion object {
        fun start(fragment: Fragment) {
            FragmentContainerActivity.start<AboutAppFragment>(fragment)
        }
    }

    override fun initUi(savedInstanceState: Bundle?) {
        super.initUi(savedInstanceState)
        setTitle(R.string.about_app)
        mBinding.versionName.text = "${getString(R.string.current_version)}${appVersionName}"
        startVideoSwitch()
    }

    override fun isNeedToolbar(): Boolean {
        return true
    }


    private var clickCount = 0
    private var clickTime = 0L
    private fun startVideoSwitch() {
        if (SettingConfig.homeEnableVideoSwitchButton) {
            return
        }
        mBinding.versionName.setOnClickListener {
            val currentTime = System.currentTimeMillis()
            if (currentTime - clickTime < 1000) {
                clickCount++
                if (clickCount >= 6) {
                    SettingConfig.homeEnableVideoSwitchButton = true
                    SettingConfig.homeEnableVideoPager = true
                    mBinding.versionName.setOnClickListener(null)
                    R.string.tips_open_video_module.toast(Toast.LENGTH_LONG)
                }
            } else {
                clickCount = 0
            }
            clickTime = currentTime
        }
    }
}